<?php
class Cl_Search extends WdkClass 
{
	protected
		/******************************************************/
		//	원본 테이블 정보
		/******************************************************/
		$search_code		= ''			,	//	
		$search_date		= '1970-01-01'	,	//	
		$search_count		= 0				,	//	
		$search_keyword		= ''			;	//	
		/******************************************************/
		//	추가 정보
		/******************************************************/
	
	/**
	 * 	
	 */
	function __construct()
	{
		parent::__construct();
		self::getDbo();
	}
	
	/**
	 *	
	 */
	public function __init($data)
	{
		parent::__init($data);
		self::dformat();
	}
	
	/**
	 *	
	 */
	public function load($search_code, $date='')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		self::__init($dbo->cLoad($search_code, $date=''));
	}
	
	/**
	 *	
	 */
	public function dformat()
	{
	
	}
	
	/**
	 *	
	 */
	public function insert()
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		
		$this->search_code	= sha1($this->search_keyword);
		$this->search_count = 1;
		$this->search_date	= date('Y-m-d');
		$data = array(	'search_code'		=>	$this->search_code,
						'search_date'		=>	$this->search_date,
						'search_count'		=>	$this->search_count,
						'search_keyword'	=>	$this->search_keyword
					);
		$dbo->insert($data);
	}
	
	/**
	 *	
	 */
	public function search($keyword='')
	{
		try
		{
			if(strlen(trim($keyword)) > 2)
			{
				$this->load(sha1($keyword));
				$dbo = self::getDbo();
				$dbo->hit($this->search_code);				
			}
		}
		catch(NoRecordException $e)
		{
			$this['search_keyword'] = $keyword;
			$this->insert();
		}
	}
	
	/**
	 *	
	 */
	private function backup($log='')
	{
		throw new MethodNotImplementedException("백업은 제공하지 않는 기능입니다.");
	}
	
	/**
	 * 
	 */
	public function getDbo()
	{
		return Wdk::model(substr(__CLASS__, 3));
	}
}